//定义store
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { adminLoginAPI } from '@/apis/admin'

export const useAdminStore = defineStore('admin', () => {
    //有点像javaBean
    //1.定义属性
    //2.定义属性的方法
    //3.决定暴露出去的接口
    //导航列表的数据管理
    //state 导航列表数据
    const adminInfo = ref({})


    //action获取导航数据的方法
    const getAdminInfo = async ({ username, password }) => {
        
        const res = await adminLoginAPI({ username, password })
        console.log(res);
        adminInfo.value = res.data;
    }

    const clearAdminInfo = async () => {
        adminInfo.value = {}
    }

    return {
        adminInfo,
        getAdminInfo,
        clearAdminInfo
    }
}, {
    persist: true//持久化存储
})
